<!DOCTYPE html>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<html>
	<head>
		<meta charset="UTF-8">
		<title>cryptochat home page</title>
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<script type="text/javascript" src="scripts/main.js"></script>
		<script type="text/javascript" src="scripts/jquery-2.1.0.js"></script>
		<script type="text/javascript">
		
			function loginFormSubmit(loginFormId, usernameInputId, publicKeyHiddenId)
			{
				console.log("Form is about to submit but, first, some useful things are going to happen...");
				var insertedUsername = $('#' + usernameInputId).val(); 
				keyPair = generateKeyPair(insertedUsername);
				localStorage.setItem('keyPair', keyPair);
				localStorage.setItem('username', insertedUsername);
				var hidden = $('#' + publicKeyHiddenId);
				hidden.val(keyPair.publicKey);
			}
			
		</script>
	</head> 
	<body>
		<div id="globalContainerDiv" class="global-container">
			<div id="loginFormDiv" class="login-box">
				<div id="titleDiv">
					<h2>
						<spring:message code="title.login" text="Login"></spring:message>
					</h2>
				</div>
				<form:form id="loginForm" action="enter" modelAttribute="chatUser"
					onsubmit="javascript:loginFormSubmit('loginForm', 'usernameText', 'publicKeyHidden');">
					<div id="usernameDiv">
						<form:input id="usernameText"  path="username"/>
					</div>
					<div id="enterButtonDiv">
						<input id="enterButton" type="submit" value="ENTER"></input>
					</div>
					<form:hidden id="publicKeyHidden" path="chatPublicKey"/>
				</form:form>
			</div>
		</div>
	</body>
</html>
